package com.wspyydshhh.mytool.slice;

import com.wspyydshhh.mytool.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;
import ohos.agp.window.dialog.CommonDialog;
import ohos.agp.window.dialog.IDialog;

public class AddAbilitySlice extends AbilitySlice {
    private Text returnBack,help;
    private Button addN,addT,addPT,changePT,changeN;
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_add);
        returnBack = (Text) findComponentById(ResourceTable.Id_returnIndex);
        help = (Text) findComponentById(ResourceTable.Id_help);
        addN = (Button) findComponentById(ResourceTable.Id_addNote);
        addT = (Button) findComponentById(ResourceTable.Id_addTask);
        addPT = (Button) findComponentById(ResourceTable.Id_addPublicTask);
        changePT = (Button) findComponentById(ResourceTable.Id_changePublicTask);
        changeN = (Button) findComponentById(ResourceTable.Id_changeNote);
        returnBack.setClickedListener(this::onClick);
        help.setClickedListener(this::onClick);
        addN.setClickedListener(this::onClick);
        addT.setClickedListener(this::onClick);
        addPT.setClickedListener(this::onClick);
        changePT.setClickedListener(this::onClick);
        changeN.setClickedListener(this::onClick);

    }

    public void onClick(Component component) {
        int id = component.getId();
        switch (id) {
            case ResourceTable.Id_returnIndex: {
                Intent intent = new Intent();
                Operation addAbility = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.wspyydshhh.mytool")
                        .withAbilityName("MainAbility")
                        .withAction("left")
                        .build();
                intent.setOperation(addAbility);
                startAbility(intent);
                break;
            }
            case ResourceTable.Id_help: {
                CommonDialog cd = new CommonDialog(this);
                cd.setTitleText("帮助");
                cd.setContentText("本应用提供三种，俩类服务，使用只需简单的点击对应按钮即可，更多信息和BUG反馈请点击”更多“");
                cd.setButton(0, "更多", new IDialog.ClickedListener() {
                    @Override
                    public void onClick(IDialog iDialog, int i) {
                        //
                        cd.destroy();
                    }
                });
                cd.setButton(1, "确定", new IDialog.ClickedListener() {
                    @Override
                    public void onClick(IDialog iDialog, int i) {
                        cd.destroy();
                    }
                });
                cd.show();
                cd.setAutoClosable(true);
                break;
            }
            case ResourceTable.Id_addNote: {
                break;
            }
            case ResourceTable.Id_addTask:{
                Intent intent = new Intent();
                System.out.println("ppppppppppppppppppppppppppppppppppppppp");
                Operation addAbility = new Intent.OperationBuilder()
                        .withDeviceId("")
                        .withBundleName("com.wspyydshhh.mytool")
                        .withAbilityName("AddMainPage")
                        .build();
                intent.setOperation(addAbility);
                startAbility(intent);
                break;
            }
            case ResourceTable.Id_addPublicTask: {
                break;
            }
            case ResourceTable.Id_changePublicTask: {
                break;
            }
            case ResourceTable.Id_changeNote: {
                break;
            }
            default: return;
        }

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
